<?php

namespace Sffi\ElementPlus\ElRule;

class Rule
{
    protected string $title;
    /**
     * @var Law[] $rules 规则
     */
    protected array $rules = [];

    public function __construct($title)
    {
        $this->title = $title;
    }

    public function addLaw(Law $law)
    {
        $this->rules[] = $law;
        return $this;
    }

    public function __toArray()
    {
        $rules = [];
        foreach ($this->rules as $rule) {
            $rules[] = $rule->__toArray();
        }
        return $rules;
    }

    /**
     * @return string
     */
    public function getTitle(): string
    {
        return $this->title;
    }

    /**
     * @param string $title
     */
    public function setTitle(string $title): self
    {
        $this->title = $title;
        return $this;
    }
}